package com.cskaoyan.controller.vx;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.bo.vxBo.WxGoodListBO;
import com.cskaoyan.bean.po.wxPo.MarketUser;
import com.cskaoyan.bean.vo.TVO;
import com.cskaoyan.bean.vo.vxVo.*;
import com.cskaoyan.config.shiro.MallToken;
import com.cskaoyan.service.vx.WxGoodsService;;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("wx/goods")
public class WxGoodsController {
    @Autowired
    WxGoodsService wxGoodsService;

    @RequestMapping("count")
    public BaseRespVo count() {
        Integer count = wxGoodsService.goodsCount();
        return BaseRespVo.ok(count);
    }

    @RequestMapping("category")
    public BaseRespVo category(Integer id) {
        WxGoodsCategoryVO wxGoodsCategoryVO = wxGoodsService.goodsCategory(id);
        return BaseRespVo.ok(wxGoodsCategoryVO);
    }
    @RequestMapping("list")
    public BaseRespVo goodList(WxGoodListBO wxGoodListBO) {
        WxGoodListVO wxGoodListVO = wxGoodsService.goodsList(wxGoodListBO);
        return BaseRespVo.ok(wxGoodListVO);
    }

    @RequestMapping("detail")
    public BaseRespVo goodDetail(Integer id) {
        MarketUser marketUser = new MarketUser();
        Subject subject = SecurityUtils.getSubject();
        if (subject.isAuthenticated()) {
            marketUser = (MarketUser) subject.getPrincipals().getPrimaryPrincipal();
        }
        WxGoodsDetailVO wxGoodsDetailVO = wxGoodsService.goodDetail(id,marketUser);
        wxGoodsService.insertFoot(id,marketUser.getId());
        return BaseRespVo.ok(wxGoodsDetailVO);
    }

    @RequestMapping("related")
    public BaseRespVo goodRelated(Integer id) {
        TVO<WxIndexGoodsVO> goodList = wxGoodsService.goodRelated(id);
        return BaseRespVo.ok(goodList);
    }
}
